package player.ui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JPanel;


public class VideoCanvas extends JPanel{
	private static final long serialVersionUID = -7691856576489032036L;

	ImageIcon icon;
	int w=600;
	int h=w;
	boolean iconVisible=true;
	int imgNum=1;
	int imgSum=3;
	public VideoCanvas(){
		super();
		
		setBackground(java.awt.Color.blue);
		icon=new ImageIcon("img\\1.jpg");
		
		new Thread(){
			public void run(){
				while(true){
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					//changeBg();
				}
			}
		}.start();
		
		this.setPreferredSize(new Dimension(100,100));
		
		this.addMouseListener(new MouseListener(){

			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent e) {
				 changeBg();
			}

			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
		});
	}
	
	void changeBg(){
		imgNum++;
		if(imgNum>imgSum){
			imgNum=1;
		}
		icon=new ImageIcon("img\\"+imgNum+".jpg");
		
		repaint();
	}
	
	
	public void paint(Graphics g){
		Graphics2D g2=(Graphics2D)g;
		if(iconVisible){
			int x=(getWidth()-w)/2;
			int y=(getHeight()-h)/2;
			g2.drawImage(icon.getImage(), 0, 0, getWidth()/2, getHeight()/2, this);
		}else{
			g2.clearRect(0, 0, getWidth(), getHeight());
		}
		System.out.println("paint VideoCanvas "+System.currentTimeMillis());
	}
}
